package com.huajin.gateway.nmap.controller;

import java.util.List;
import java.util.Map;

import com.huajin.gateway.util.PageUtils;
import com.huajin.gateway.util.Query;
import com.huajin.gateway.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.huajin.gateway.nmap.domain.AssetDO;
import com.huajin.gateway.nmap.service.AssetService;


/**
 * 资产表
 *
 * @author huajin
 * @email 1992lcg@163.com
 * @date 2018-10-30 18:49:51
 */


@Controller
@RequestMapping("/nmap/asset")
public class AssetController {
    @Autowired
    private AssetService assetService;

    @ResponseBody
    @GetMapping("/list")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<AssetDO> assetList = assetService.list(query);
        int total = assetService.count(query);
        PageUtils pageUtils = new PageUtils(assetList, total);
        return pageUtils;
    }


    /**
     * 保存
     */
    @ResponseBody
    @PostMapping("/save")
    public R save(@RequestBody AssetDO asset) {
        if (assetService.save(asset) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    public R update(@RequestBody AssetDO asset) {
        assetService.update(asset);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    @ResponseBody
    public R remove(Integer id) {
        if (assetService.remove(id) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @PostMapping("/batchRemove")
    @ResponseBody
    public R remove(@RequestParam("ids[]") Integer[] ids) {
        assetService.batchRemove(ids);
        return R.ok();
    }

}
